<?php

class componentComponents extends sfComponents
{
    public function executeSearch()
    {

    }
    public function executeAlert()
    {

    }
    public function executeMultiLanguage()
    {

    }
    public function executeFooterInformation()
    {

    }
    public function executeHomeLeftMenu()
    {

    }
    public function executeCountrySelectOption()
    {
        $this->countrySelected = $this->countrySelected;
        $this->countryName = $this->countryName;
        $this->countryId = $this->countryId;
    }
    public function executeSubmenu()
    {
        $distDB = MlmDistributorPeer::retrieveByPK($this->param);

        $this->distDB = $distDB;

        $c = new Criteria();
        $c->add(MlmIbPeer::DIST_ID, $this->getUser()->getAttribute(Globals::SESSION_DISTID));
        $c->add(MlmIbPeer::STATUS_CODE, Globals::STATUS_ACTIVE);

        $this->mlmIb = MlmIbPeer::doSelectOne($c);
    }
    public function executeHeaderInformation()
    {

    }

    function getAccountBalance($distributorId, $accountType)
    {
        $query = "SELECT SUM(credit-debit) AS SUB_TOTAL FROM mlm_account_ledger WHERE dist_id = " . $distributorId . " AND account_type = '" . $accountType . "'";

        $connection = Propel::getConnection();
        $statement = $connection->prepareStatement($query);
        $resultset = $statement->executeQuery();

        if ($resultset->next()) {
            $arr = $resultset->getRow();
            if ($arr["SUB_TOTAL"] != null) {
                return $arr["SUB_TOTAL"];
            } else {
                return 0;
            }
        }
        return 0;
    }
}